<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Assistance extends CI_Controller {
	public function index()
	{
		page('Assistance/index', 'Assistance', null);
	}
        
        public function Contact()
	{
            $this->form_validation->set_rules('service', 'service', 'required');
            $this->form_validation->set_rules('sujet', 'sujet', 'required');
            $this->form_validation->set_rules('message', 'message', 'required');

		if ($this->form_validation->run() == FALSE)
		{
			page('Assistance/contact', 'Contact', null);
		}
		else
		{
                  $headers = 'From: "Cesi" <no_reply@cesi.fr>'."\r\n".
                             'Reply-To: webmaster@example.com' . "\r\n";
                  $headers .= 'MIME-Version: 1.0' . "\r\n";
                  $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
                  $objet = $this->input->post('sujet');
                  $message = $this->input->post('message');

                  if(!mail($this->input->post('service'), $objet, $message, $headers))
                  $data['message'] = '<br><br><br>Problème lors de l\'envoi du mail sur l\'adresse email :'.$this->input->post('service');
                  else
                  $data['message'] = '<br><br><br>Votre message à été envoyé sur l\'adresse email : '.$this->input->post('service');
                        page('Assistance/contact_success', 'Message envoyé', $data);
		}
	}
        
        public function FAQ()
	{
		page('Assistance/faq', 'FAQ', null);
	}
}